package org.mags.object.common;

public class BooleanParserFormatter {
	public Boolean parse(Object value) {
		boolean b = false;
		if(value==null) return null; 
		if(value instanceof String) {
			String string = (String)value;
			if(!"N".equals(string)
			 &&!"NO".equalsIgnoreCase(string)
			 &&!"FALSE".equalsIgnoreCase(string)
			 &&!"F".equalsIgnoreCase(string)
			 &&!"".equals(string))
				b = true;
		} else if(value instanceof Number) {
			double d = ((Number)value).doubleValue();
			if(d!=0)
				b = true;
		} else if (value instanceof Boolean)
			b = ((Boolean)value).booleanValue();
		return b;		
	}
	public String toText(Boolean value) {
		 return value==null?null:value.toString();
	}	
}
